prepare-root: Changes made to find_proc_cmdline_key
authorEric Curtin <ecurtin@redhat.com>
Tue, 22 Aug 2023 12:11:30 +0000 (13:11 +0100)
committerEric Curtin <ecurtin@redhat.com>
Tue, 22 Aug 2023 15:43:20 +0000 (16:43 +0100)
Used strspn based on feedback from similar function.

src/switchroot/ostree-mount-util.h

index 1c15fe9004874b70f1366b7773e67e88fbea006f..eb79efdfbfb1fe2db7682df8d06c2ec764329d59 100644 (file)
@@ -87,29 +87,26 @@ cleanup_free (void *p)
 static inline char *
 find_proc_cmdline_key (const char *cmdline, const char *key)
 {
-  char *ret = NULL;
-  size_t key_len = strlen (key);
-
-  const char *iter = cmdline;
-  while (iter != NULL)
+  const size_t key_len = strlen (key);
+  for (const char *iter = cmdline; iter;)
     {
       const char *next = strchr (iter, ' ');
-      const char *next_nonspc = next;
-      while (next_nonspc && *next_nonspc == ' ')
-        next_nonspc += 1;
       if (strncmp (iter, key, key_len) == 0 && iter[key_len] == '=')
         {
           const char *start = iter + key_len + 1;
           if (next)
-            ret = strndup (start, next - start);
-          else
-            ret = strdup (start);
-          break;
+            return strndup (start, next - start);
+
+          return strdup (start);
         }
-      iter = next_nonspc;
+
+      if (next)
+        next += strspn (next, " ");
+
+      iter = next;
     }
 
-  return ret;
+  return NULL;
 }
 
 /* This is an API for other projects to determine whether or not the